import React, { Component } from 'react'
import ReactDOM from 'react-dom' //注意: 引入react-dom.就按照v17的方式引入

export default class Test extends Component {
  constructor() {
    super()
    // 1. 创建容器dom
    this.container = document.createElement('div')
  }
  render() {
    // createPortal会根据jsx生成虚拟dom,创建真实dom.并添加到container中
    return ReactDOM.createPortal(<div>test</div>, this.container)
  }

  componentDidMount() {
    document.getElementById('wrap').appendChild(this.container)
  }
  componentWillUnmount() {
    document.getElementById('wrap').removeChild(this.container)
  }
}
